/**
 * 月结应收款管理初始化
 */
var MonthbalanceDetail = {
    id: "MonthbalanceDetailTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
MonthbalanceDetail.initColumn = function () {
    return [
        {field: 'selectItem', radio: false},
            {title: '账单编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '账目来源', field: 'income', visible: true, align: 'center', valign: 'middle',
                formatter : function(value,row,index){
                    if(row.income=='1'){
                        return "收货";
                    }else if(row.income=='2'){
                        return "自提";
                    }else if(row.income=='3'){
                        return "配送";
                    }else if(row.income=='4'){
                        return "中转";
                    }else if(row.income=='5'){
                        return "改单";
                    }
                }
            },
            {title: '车次编号', field: 'incomeName', visible: true, align: 'center', valign: 'middle'},//收货，配送，中转 则为train_id  改单 自提则为order_id
            {title: '账单状态', field: 'status', visible: true, align: 'center', valign: 'middle',formatter : function(value,row,index){
                if(row.status=='0'){
                    return "待结算";
                }else if(row.status=='1'){
                    return "已结算";
                }
            }
            },
            {title: '收货人', field: 'traner', visible: true, align: 'center', valign: 'middle'},
            {title: '应收金额', field: 'money', visible: true, align: 'center', valign: 'middle'},
            {title: '创建日期', field: 'createtime', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人员', field: 'creater', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
MonthbalanceDetail.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        MonthbalanceDetail.seItem = selected.join(",");
        return true;
    }
};

/**
 *
 */
MonthbalanceDetail.openPrintMonthbalanceDetail = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    var ids='';
    if(selected.length == 0){
        Feng.info("请先选中表格中的记录！");
        return false;
    }else{
       //var train_no=selected[0].
    }
    alert(ids);
//    alert( $('#' + this.id).bootstrapTable('getSelections'));
   // var w = window.open(Feng.ctxPath + "/monthbalanceDetail/monthbalanceDetail_print");
    // var index = layer.open({
    //     type: 2,
    //     title: '打印月结应收款',
    //     area: ['800px', '420px'], //宽高
    //     fix: false, //不固定
    //     maxmin: true,
    //     content: Feng.ctxPath + '/monthbalanceDetail/monthbalanceDetail_print'
    // });
    // layer.full(index);
    // this.layerIndex = index;
};

/**
 * 打开查看月结应收款详情
 */
MonthbalanceDetail.openMonthbalanceDetailDetail = function () {

    // if (this.check()) {
    //     var index = layer.open({
    //         type: 2,
    //         title: '月结应收款详情',
    //         area: ['800px', '420px'], //宽高
    //         fix: false, //不固定
    //         maxmin: true,
    //         content: Feng.ctxPath + '/monthbalanceDetail/monthbalanceDetail_update/' + MonthbalanceDetail.seItem.id
    //     });
    //     this.layerIndex = index;
    // }
};

/**
 * 删除月结应收款
 */
MonthbalanceDetail.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/monthbalanceDetail/delete", function (data) {
            Feng.success("删除成功!");
            MonthbalanceDetail.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("monthbalanceDetailId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询月结应收款列表
 */
MonthbalanceDetail.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    MonthbalanceDetail.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = MonthbalanceDetail.initColumn();
    var table = new BSTable(MonthbalanceDetail.id, "/monthbalanceDetail/list", defaultColunms);
    table.setPaginationType("client");
    layui.use('layer', function () {  })
    MonthbalanceDetail.table = table.init();
});
